| Conditions | 1 |
| Paths | 1 |
| Total Lines | 90 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var chai = require('chai'); |
||
| 11 | describe('Template', function() { |
||
| 12 | before( function(done) { |
||
| 13 | Manager.instance.init() |
||
| 14 | .then(function () { |
||
| 15 | this.fixture = { |
||
| 16 | template: fse.readFileSync(__dirname + '/fixtures/templates/article.html', 'utf-8'), |
||
| 17 | articleEach: fse.readFileSync(__dirname + '/fixtures/templates/article-each-abe.html', 'utf-8'), |
||
| 18 | templateKeys: fse.readFileSync(__dirname + '/fixtures/templates/article-keys.html', 'utf-8') |
||
| 19 | } |
||
| 20 | done() |
||
| 21 | |||
| 22 | }.bind(this)) |
||
| 23 | }); |
||
| 24 | |||
| 25 | /** |
||
| 26 | * getAbeImport |
||
| 27 | * |
||
| 28 | */ |
||
| 29 | it('cmsTemplates.template.getStructureAndTemplates()', function() { |
||
| 30 | var res = cmsTemplates.template.getStructureAndTemplates() |
||
| 31 | chai.expect(res.templates.length).to.be.above(1); |
||
| 32 | }); |
||
| 33 | |||
| 34 | /** |
||
| 35 | * getAbeImport |
||
| 36 | * |
||
| 37 | */ |
||
| 38 | it('cmsTemplates.template.getAbeImport()', function() { |
||
| 39 | var res = cmsTemplates.template.getAbeImport(this.fixture.template) |
||
| 40 | chai.expect(res).to.have.length(4); |
||
| 41 | }); |
||
| 42 | |||
| 43 | /** |
||
| 44 | * includePartials |
||
| 45 | * |
||
| 46 | */ |
||
| 47 | it('cmsTemplates.template.includePartials()', function() { |
||
| 48 | var template = cmsTemplates.template.includePartials(this.fixture.template) |
||
| 49 | chai.expect(template).to.contain("{{abe type='text' key='title' desc='titre' tab='default'}}"); |
||
| 50 | }); |
||
| 51 | |||
| 52 | /** |
||
| 53 | * cmsTemplates.template.getTemplate |
||
| 54 | * |
||
| 55 | */ |
||
| 56 | it('cmsTemplates.template.getTemplate()', function() { |
||
| 57 | var template = cmsTemplates.template.getTemplate('article') |
||
| 58 | chai.expect(template).to.contain("{{abe type='text' key='title' desc='titre' tab='default' order='1'}}"); |
||
| 59 | }); |
||
| 60 | |||
| 61 | /** |
||
| 62 | * getTemplate |
||
| 63 | * |
||
| 64 | */ |
||
| 65 | it('cmsTemplates.template.getSelectTemplateKeys()', function() { |
||
| 66 | const pathTemplate = path.join(config.root, config.templates.url) |
||
| 67 | cmsTemplates.template.getSelectTemplateKeys(pathTemplate) |
||
| 68 | .then((whereKeys) => { |
||
| 69 | chai.expect(whereKeys.indexOf('abe_meta.date')).to.be.above(-1); |
||
| 70 | }) |
||
| 71 | }); |
||
| 72 | |||
| 73 | /** |
||
| 74 | * getTemplate |
||
| 75 | * |
||
| 76 | */ |
||
| 77 | it('cmsTemplates.template.execRequestColumns()', function() { // templateKeys |
||
| 78 | const pathTemplate = path.join(config.root, config.templates.url) |
||
| 79 | var ar = cmsTemplates.template.execRequestColumns(this.fixture.templateKeys) |
||
| 80 | chai.expect(ar.indexOf('abe_meta.date')).to.be.above(-1); |
||
| 81 | }); |
||
| 82 | |||
| 83 | /** |
||
| 84 | * cmsTemplates.insertDebugtoolUtilities |
||
| 85 | * |
||
| 86 | */ |
||
| 87 | it('cmsTemplates.insertDebugtoolUtilities()', function() { |
||
| 88 | var txt = cmsTemplates.insertDebugtoolUtilities('</body>'); |
||
| 89 | chai.expect(txt.length).to.above(10); |
||
| 90 | }); |
||
| 91 | |||
| 92 | /** |
||
| 93 | * cmsTemplates.encodeAbeTagAsComment |
||
| 94 | * |
||
| 95 | */ |
||
| 96 | it('cmsTemplates.encodeAbeTagAsComment()', function() { |
||
| 97 | var txt = cmsTemplates.encodeAbeTagAsComment(this.fixture.articleEach); |
||
| 98 | chai.expect(txt.indexOf('{')).to.equal(-1); |
||
| 99 | }); |
||
| 100 | }); |
||
| 101 |